﻿@using ERP.WebUI
@model SearchModuleModel
@{
    ViewBag.Title = ViewBag.CurrentTitle;
    var setButton = new ButtonModel();
    var editButton = new ButtonModel();
    var deleteButton = new ButtonModel();
    setButton = ViewBag.setButton;
    editButton = ViewBag.Edit;
    deleteButton = ViewBag.Delete;
    var createButton = new ButtonModel();
    createButton = ViewBag.Create;
}
@section css{
    @Styles.Render("~/bundles/css/jqueryui")
}
<div id="content-body" class="row-fluid">
    <div class="span22">
        <!--操作 -->
        <div class="widget-box">
            <div class="widget-title">
                <span class="icon"><i class="icon-search"></i></span>
                <h5>查询条件</h5>
            </div>
            <div class="widget-content nopadding">
                <form class="form-horizontal search-form" method="post" name="basic_validate" novalidate="novalidate">

                    <div class="control-group">
                        <div class="search-group">
                            <label class="search-label">@Html.DisplayNameFor(t => t.Name)</label>
                            <div class="span2 search-input">
                                @Html.TextBoxFor(t => t.Name)
                            </div>
                        </div>

                        <div class="search-group">
                            <label class="search-label">@Html.DisplayNameFor(t => t.LinkUrl)</label>
                            <div class="span2 search-input">
                                @Html.TextBoxFor(t => t.LinkUrl)
                            </div>
                        </div>

                        <div class="search-group">
                            <label class="search-label">@Html.DisplayNameFor(t => t.ParentName)</label>
                            <div class="span2 search-input">
                                @Html.DropDownListFor(t => t.ParentId, Model.ParentModuleItems)
                            </div>
                        </div>
                    </div>

                    <div class="control-group">
                        <div class="search-group">
                            <label class="search-label">@Html.DisplayNameFor(t => t.IsMenu)</label>
                            <div class="span2 search-input">
                                @Html.DropDownListFor(t => t.IsMenu, Model.EnabledItems)
                            </div>
                        </div>
                        <div class="search-group">
                            <label class="search-label">@Html.DisplayNameFor(t => t.Enabled)</label>
                            <div class="span2 search-input">
                                @Html.DropDownListFor(t => t.Enabled, Model.EnabledItems)
                            </div>
                        </div>
                    </div>

                    <div class="form-actions form-operate text-right ">
                        <button type="button" class="btn btn-danger" onclick="ClearForm($('.search-form'));">
                            <span class="icon-bullhorn"></span>清空
                        </button>
                        <button type="button" class="btn btn-success" onclick="Search()">
                            <span class="icon-search"></span>搜索
                        </button>
                        @if (createButton != null)
                        {
                            <button type="button" class="btn btn-primary" onclick="Create()">
                                <span class="@createButton.Icon"></span>@createButton.Text
                            </button>
                        }
                    </div>

                </form>

            </div>
        </div>

        <!--列表-->
        <div class="widget-box">
            <div class="widget-title">
                <span class="icon"><i class="icon-th"></i></span>
                <h5>模块列表</h5>
            </div>
            <div class="widget-content nopadding">
                <table class="table table-bordered data-table">
                    <thead>
                        <tr>
                            <th width="5%">序号</th>
                            <th width="16%">模块(菜单)名称</th>
                            <th width="10%">模块编码</th>
                            <th width="12%">上级模块</th>
                            <th width="20%">链接地址</th>
                            <th width="7%">排序</th>
                            <th width="8%">是否菜单</th>
                            <th width="8%">是否激活</th>
                            <th width="15%">操作</th>
                        </tr>
                    </thead>
                    <tbody>
                    </tbody>
                </table>
            </div>
        </div>

    </div>
</div>

@section scripts{
    @Scripts.Render("~/bundles/jqueryui")
    <script type="text/javascript">
        var oTable = null;

        $(function () {
            var actionUrl = "@Url.Action("List")?rand=" + Math.random();
            var aoColumns = [
                    { "sName": "SortId", "bSortable": false },
                    {
                        "sName": "Name",
                        "bSortable": false,
                        "fnRender": function (oObj) {
                            if (oObj.aData[3] != "") {
                                return "<label class='th-label'>[ " + oObj.aData[1] + " ]</label>";
                            } else {
                                return oObj.aData[1];
                            }
                        }
                    },
                    { "sName": "Code", "bSortable": false },
                    { "sName": "ParentName", "bSortable": false },
                    { "sName": "LinkUrl", "bSortable": false },
                    { "sName": "OrderSort", "bSortable": false },
                    { "sName": "IsMenu", "bSortable": false, },
                    { "sName": "Enabled", "bSortable": false, },
                    {
                        "sName": "Id",
                        "bSortable": false,
                        "fnRender": function (oObj) {
                            var btnArray = "";
                            if (oObj.aData[3] != "") {
                                @if (setButton != null)
                                {
                                    <text>btnArray += '<button type="submit" class="btn btn-success btn-normal" title="@setButton.Text" onclick="SetButton(' + oObj.aData[oObj.aData.length - 1] + ')"><span class="@setButton.Icon"></span></button>'</text>
                                }
                            }
                            @if (editButton != null)
                            {
                                <text>btnArray += '<button type="submit" class="btn btn-primary btn-normal" title="@editButton.Text" onclick="Edit(' + oObj.aData[oObj.aData.length - 1] + ')"><span class="@editButton.Icon"></span></button>'</text>
                            }
                            @if (deleteButton != null)
                            {
                                <text>btnArray += '<button type="submit" class="btn btn-danger btn-normal" title="@deleteButton.Text " onclick="Delete(' + oObj.aData[oObj.aData.length - 1] + ')"><span class="@deleteButton.Icon"></span></button>'</text>
                            }
                            return btnArray;
                        }
                    }
            ];
            //初始化表格
            oTable = InitDatatables($(".data-table"), actionUrl, aoColumns, oTable);

        });

                //Icon点击事件
                function fnFormatDetails(nTr) {
                    var aData = oTable.fnGetData(nTr);
                    var sOut = '<table class="table table-bordered data-table" cellpadding="5" cellspacing="0">';
                    sOut += '<tr>';
                    sOut += '<td width="5%">---</td>';
                    sOut += '<td width="15%">模块(菜单)名称</td>';
                    sOut += '<td width="10%">模块编码</td>';
                    sOut += '<td width="12%">上级模块</td>';
                    sOut += '<td width="18%">链接地址</td>';
                    sOut += '<td width="8%">排序</th>';
                    sOut += '<td width="8%">是否激活</td>';
                    sOut += '<td width="22%">操作</td>';
                    sOut += '</tr>';
                    sOut += '<tr>';
                    sOut += '<td width="5%"></td>';
                    sOut += '<td width="15%">模块(菜单)名称</td>';
                    sOut += '<td width="10%">模块编码</td>';
                    sOut += '<td width="12%">上级模块</td>';
                    sOut += '<td width="18%">链接地址</td>';
                    sOut += '<td width="8%">排序</th>';
                    sOut += '<td width="8%">是否激活</td>';
                    sOut += '<td width="22%">操作</td>';
                    sOut += '</tr>';
                    sOut += '</table>';
                    return sOut;
                }

                //查询
                function Search() {
                    var filterdata = $(".search-form").serialize();
                    oTable.fnReloadAjax("@Url.Action("List")?rand=" + Math.random() + "&" + filterdata);
                }

                //新增
                function Create() {
                    var actionUrl = "@Url.Action("Create")";
                    location.href = actionUrl;
                }

                //编辑
                function Edit(id) {
                    var actionUrl = "@Url.Action("Edit")" + "/" + id;
                    location.href = actionUrl;
                }

                //删除
                function Delete(id) {
                    var actionUrl = "@Url.Action("Delete")";
                    var param = { Id: id }
                    DeleteRecord(actionUrl, param, oTable);
                }

                //设置按钮
                function SetButton(id) {
                    var actionUrl = "@Url.Action("SetButton")" + "/" + id;
                    location.href = actionUrl;
                }
    </script>
}